package com.yc.game.cms.controller;

import com.github.pagehelper.PageInfo;
import com.yc.game.cms.common.ServerResponse;
import com.yc.game.cms.pojo.Money;
import com.yc.game.cms.service.MoneyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class MoneyController {
    @Autowired
    private MoneyService moneyService;

    /**
     * 查询所有保证金
     */
    @RequestMapping("money/getAll")
    public String getAllMoney(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                              @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                              ModelMap modelMap) {
        PageInfo<Money> pageInfo = moneyService.getAll(pageNum, pageSize);
        modelMap.addAttribute("pageInfo", pageInfo);
        return "money";
    }

    /**
     * 更新金额
     */
    @PostMapping("money/updateCategory")
    @ResponseBody
    public ServerResponse updateCategory(Money money) {
        int result = moneyService.update(money);
        if (result > 0) {
            return ServerResponse.createBySuccessMessage("操作成功");
        }
        return ServerResponse.createByErrorMessage("操作失败");
    }

    /**
     * 删除保证金用户
     */
    @RequestMapping("money/deleteById")
    @ResponseBody
    public ServerResponse deleteById(@RequestParam("moneyId") Integer moneyId) {
        int result = moneyService.deleteById(moneyId);
        if (result > 0) {
            return ServerResponse.createBySuccessMessage("操作成功");
        }
        return ServerResponse.createByErrorMessage("操作失败");
    }

}
